<?php require_once('../src/session_start.inc.php'); ?>
<?php
require_once('../src/functions.php');

require_once('../src/Exchange.class.php');
$exchange = new Exchange();

$error = false;


// Dispatcher
if (isset($_POST['send']) && $_POST['send']=='true') {
	//$error = "Cette fonction n'est pas encore implémentée.";

    if (isset($_POST['rate']) && $_POST['rate']!='') {
		$exchange->currency_from = $_POST['from'];
		$exchange->currency_to = $_POST['to'];
		$exchange->rate = $_POST['rate'];
		$exchange->save();
		header('Location: change.php?'.time());
    } else {
        $error = "Le champ ne peut être vide";
    }
} else if ( isset($_GET['nodata']) ) {
	$error = "Une erreur est survenue";
	//log_error("l'edition de la classe '" . $class . "' BUG (ID manquant)");
}

?>
<?php require_once('admin_header.php'); ?>

<h2>Taux de change</h2>

<p class="message">
	<span class="biginfo">Le taux de change enregistré est de:<br/>
	<b><?php echo Exchange::getRate('EUR', 'DZD', true, true) ?></b></span><br/>
	<span class="info">( <?php echo Exchange::getRate('DZD', 'EUR', true) ?> )</span>
</p>

<p class="currency">
	<a href="change_update.php?from=EUR&to=DZD"><?php echo getIcon('money') ?>Mettre a jour via la bourse <?php echo getIcon('money') ?></a>
</p>

<p class="error"><?php echo $error; ?></p>

<form method="post" action="change.php">
	<fieldset>
	<legend>Modifier le taux de change</legend>
    <p>
        <label for="rate">Taux : </label>
        <input type="text" id="rate" name="rate" value="<?php echo Exchange::getRate('EUR', 'DZD') ?>" tabindex="1" />
    </p>
    <p>
        <input type="hidden" name="send" value="true" />
        <input type="hidden" name="from" value="EUR" />
        <input type="hidden" name="to" value="DZD" />
        <input type="reset" class="reset" value="Effacer" />
        <input type="submit" class="submit" value="Enregistrer" />
    </p>
	</fieldset>
</form>

<?php require_once('admin_footer.php'); ?>